package com.goods.controller.business;

import com.goods.business.service.SupplierService;
import com.goods.common.model.business.Supplier;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.SupplierVO;
import com.goods.common.vo.system.DepartmentVO;
import com.goods.common.vo.system.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * projectName: goods
 *
 * @author: ysc
 * time: 2022/12/2 22:12 周五
 * description:
 */
@RestController
@Api(tags = "业务管理-物资来源")
@RequestMapping("/business/supplier")
public class SupplierController {


    @Autowired
    private SupplierService supplierService;



    //物资来源分页列表展示
    @ApiOperation(value = "物资来源分页列表展示")
    @GetMapping("/findSupplierList")
    public ResponseBean<PageVO<SupplierVO>> findSupplierList(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                                             @RequestParam(value = "pageSize") Integer pageSize,
                                                             @RequestParam(value = "name") String name){
        PageVO<SupplierVO> supplierList =supplierService.findSupplierList(pageNum,pageSize,name);
        return ResponseBean.success(supplierList);
    }



    //添加物资来源
    @ApiOperation(value = "添加来源")
    @PostMapping("/add")
    public ResponseBean add(@RequestBody @Validated SupplierVO supplierVO){
        supplierService.add(supplierVO);
        return ResponseBean.success();
    }

    //删除物资来源
    @ApiOperation(value = "删除物资来源")
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        supplierService.delete(id);
        return ResponseBean.success();
    }


    //编辑物资来源
    @ApiOperation(value = "编辑物资来源")
    @GetMapping("/edit/{id}")
    public ResponseBean edit(@PathVariable Long id){
        SupplierVO supplierVO =supplierService.edit(id);
        return ResponseBean.success(supplierVO);
    }


    //更新物资来源
    @ApiOperation(value = "更新物资来源")
    @PutMapping("/update/{id}")
    public ResponseBean update(@PathVariable Long id,@RequestBody SupplierVO supplierVO){
        supplierService.update(id,supplierVO);
        return ResponseBean.success(supplierVO);
    }

}
